#include "DXUT.h"
#include "DXUTCamera.h"
#include "RenderInformation.h"

#define STARCOUNT 1000

struct TexVertex
{
	D3DXVECTOR3 Pos;
	D3DXVECTOR2 Tex;
};

class Skybox {
private:
  
	ID3D11Device*				m_pd3dDevice;
	
	D3DXVECTOR4					m_Sun;
	D3DXVECTOR4					m_Moon;

	D3DXMATRIX					m_RotSun;
	D3DXMATRIX					m_RotMoon;
	D3DXMATRIX					m_RotStars;

	// Skybox-buffer
	ID3D11Buffer*				m_pVertexBuffer;
	ID3D11Buffer*				m_pIndexBuffer;
	WORD						indexSize;

	ID3D11Buffer*				m_pSunVertexBuffer;
	ID3D11Buffer*				m_pMoonVertexBuffer;
	ID3D11Buffer*				m_pStarVertexBuffer;
	ID3D11Buffer*				m_pStarInstanceBuffer;

	// Shader-settings
	ID3D11InputLayout*			m_pVertexLayout;
	ID3D11InputLayout*			m_pVertexLayoutTextured;
	ID3D11InputLayout*			m_pVertexLayoutInstanced;

	ID3D11VertexShader*			m_pSkyVertexShader;
	ID3D11PixelShader*			m_pSkyPixelShader;

	ID3D11VertexShader*			m_pSunVertexShader;
	ID3D11PixelShader*			m_pSunPixelShader;

	ID3D11VertexShader*			m_pStarVertexShader;
	ID3D11PixelShader*			m_pStarPixelShader;

	ID3D11ShaderResourceView*   m_pTextureRVGlow;
	ID3D11ShaderResourceView*   m_pTextureRVColor;
	ID3D11ShaderResourceView*   m_pTextureRVSun;
	ID3D11ShaderResourceView*   m_pTextureRVStar;

	ID3D11Buffer*				m_pcbVSPerFrame11;
	ID3D11Buffer*				m_pcbPSPerFrame11;
	ID3D11Buffer*				m_pcbVSPerObject11;

	/* States */
	ID3D11SamplerState*			m_pSamplerState11;
	ID3D11BlendState*			m_pBlendState11;
	ID3D11DepthStencilState*	m_pDepthStencilState11;
	/* States */
public:

	Skybox();
	~Skybox();

	void generateSkyDome(ID3D11Device* pd3dDevice);

	float setTime(double dTime, float* moonlight);

	HRESULT OnD3D11CreateDevice( ID3D11Device* pd3dDevice);
	void    OnD3D11ResizedSwapChain( const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc );
    void    D3D11Render( CBaseCamera * cam, ID3D11DeviceContext* pd3dImmediateContext );
    void    OnD3D11ReleasingSwapChain();
    void    OnD3D11DestroyDevice();
};